package main.java.sales;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * SalesReducer
 *
 * @author zhangyimin
 * @version 1.0
 * @date 2018-11-07 上午9:50
 */
public class SalesReducer extends Reducer<Text,DoubleWritable,Text,Text> {

    @Override
    protected void reduce(Text key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException {
        Double total=0.00;
        Integer totalCount=0;
        for (DoubleWritable amount:values){
            total+=amount.get();
            totalCount++;
        }
        context.write(key,new Text(total+"\t"+totalCount));
    }
}
